package com.neuedu.jdbc.dao;

import com.neuedu.jdbc.po.Dept;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;
import java.util.Map;

/**
 * @author 金山
 * 项目：jdbc
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2024/11/813:42
 */
public class DeptDaoTest {
    //new 对象
    DeptDao deptDao = new DeptDao();
    @Test
    public void selectAll() {

        //查询
        List list = deptDao.selectAll();

        // 遍历数据
        list.forEach(System.out::println);

    }

    @Test
    public void selectByIdselectByIdMap() {
        //new 对象


        //查询
        int id = 10;
        Map<String,Object> row = deptDao.selectByIdMap(id);

        // 遍历数据
        System.out.println("row = " + row);

        int deptNo = (int) row.get("deptno");
        String dname = (String) row.get("dname");
        String loc = (String) row.get("loc");

        System.out.println("deptNo = " + deptNo);
        System.out.println("dname = " + dname);
        System.out.println("loc = " + loc);


    }


    @Test
    public void selectById() {
        //new 对象


        //查询
        int id = 10;
        Dept dept = deptDao.selectById(id);

        Integer deptno = dept.getDeptno();
        String dname = dept.getDname();
        String loc = dept.getLoc();

        System.out.println("dept = " + dept);


    }

    @Test
    public void updateById() {
        System.out.println("DeptDaoTest.updateById");



        //根据主键查询
        int id = 10;
        Dept dept = deptDao.selectById(id);

        //设置更新的字段
        dept.setDname("测试Dao");
        int count = deptDao.updateById(dept);

        System.out.println("count = " + count);

    }

    @Test
    public void insert() {

        Dept dept = new Dept(4567,"JDBC","Harbin");


        int insert = deptDao.insert(dept);
        System.out.println("insert = " + insert);

        Dept dept1 = deptDao.selectById(4567);
        System.out.println("dept1 = " + dept1);

    }

    @Test
    public void deleteById() {
        int deptno = 4567;
        int count = deptDao.deleteById(deptno);

        System.out.println("count = " + count);

        Assert.assertEquals(count,1);

    }


}